package com.lcz.googleplay.utils;

import android.view.View;
import android.view.ViewParent;
import android.widget.GridView;

import com.lcz.googleplay.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;

/**
 * Created by hp on 2016/10/26.
 */

public class ViewUtils {
    public static ImageLoader imageLoader;// 根据图片url抓取图片
    public static DisplayImageOptions options;// 抓取图片参数


    public static ImageLoader getImageLoader() {
        // 初始化ImageLoader
        imageLoader = ImageLoader.getInstance();
        ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(
                UIUtils.getActivity()).build();
        imageLoader.init(configuration);
        return imageLoader;
    }

    public static DisplayImageOptions getOptions() {
        // 图片加载时显示的图片
        options = new DisplayImageOptions.Builder().cacheOnDisk(false)
                .cacheInMemory(true).showImageOnLoading(R.drawable.ic_default)//加载中显示
                .showImageOnFail(R.drawable.ic_default)
                .displayer(new FadeInBitmapDisplayer(1000)).build();
        return options;

    }
    public static void removeParent(View view) {
        ViewParent parent = view.getParent();
        if (parent instanceof GridView) {
            GridView gridView = (GridView) parent;
            gridView.removeView(view);
        }


    }
}
